<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Conf\ConfModel;

use Srv\Libs\Frame\Conf;

final class GPlayAuthConfGroup
{
    private array $GPlayAuthConfGroupNameList       = [];       // GPlayAuthConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $GPlayAuthConfList          = [];
        $groupNameList              = Conf::getGroupNameList(GPlayAuthConf::PREFIX);
        if(count($groupNameList) < 1) return $GPlayAuthConfList;
        foreach ($groupNameList as $groupName){
            $GPlayAuthConf          = $this->getByGroupName($groupName);
            if($GPlayAuthConf instanceof GPlayAuthConf) $GPlayAuthConfList[$groupName] = $GPlayAuthConf;
        }
        return $GPlayAuthConfList;
    }

    /**
     * @param string $groupName
     * @return GPlayAuthConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?GPlayAuthConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->GPlayAuthConfGroupNameList[$groupName]) && $this->GPlayAuthConfGroupNameList[$groupName] instanceof GPlayAuthConf) return $this->GPlayAuthConfGroupNameList[$groupName];
        $confData                                       = Conf::getGroupList(GPlayAuthConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->GPlayAuthConfGroupNameList[$groupName]   = new GPlayAuthConf($confData, $groupName);
        return $this->GPlayAuthConfGroupNameList[$groupName];
    }
}